import Vue from 'vue'
import App from './App'
import router from './router'
import store from "./store";
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {initMenu} from '../utils/menus';
import 'font-awesome/css/font-awesome.min.css';
import * as filters from "./filters/filters";
import moment from 'moment';
import uploader from 'vue-simple-uploader';
import $ from 'jquery';
import JsonViewer from 'vue-json-viewer/ssr'
import 'vue-json-viewer/style.css'
// 第一步引入样式文件
import 'bpmn-js/dist/assets/diagram-js.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn.css'
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-embedded.css';
import 'bpmn-js/dist/assets/bpmn-font/css/bpmn-codes.css'
import 'bpmn-js-properties-panel/dist/assets/bpmn-js-properties-panel.css'
// 自定义节点
import './views/activity/innerModel/panel/customPalette.scss';
// 解决消息重复
import {myMessage} from '../utils/resetMessage';


Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key]);
});

// 添加 Vue 实例方法
import {postKeyValueRequest} from "../utils/api";
import {postRequest} from "../utils/api";
import {putRequest} from "../utils/api";
import {getRequest} from "../utils/api";
import {deleteRequest} from "../utils/api";
import {validateCode} from "../utils/api";
import {downloadAttachment} from "../utils/api";
// 以后在任意vue页面中需要使用这些封装的方法时不用再导入，直接使用this.postKeyValueRequest,通过 this. 就能访问这些封装的方法！
Vue.prototype.postKeyValueRequest=postKeyValueRequest;
Vue.prototype.postRequest=postRequest;
Vue.prototype.putRequest=putRequest;
Vue.prototype.getRequest=getRequest;
Vue.prototype.deleteRequest=deleteRequest;
Vue.prototype.validateCode =validateCode;
Vue.prototype.downloadAttachment=downloadAttachment;
Vue.prototype.initMenu=deleteRequest;
// 时间格式化过滤{{scope.row.loginTime| dateFormat('YYYY-MM-DD HH:mm:ss')}}
// 参考文献：https://mp.weixin.qq.com/s/6LIVvWdEgn_zGoeNdDTrvA
Vue.prototype.moment = moment;
Vue.filter('dateFormat',function(data,format){
  return moment(data).format(format);
})

Vue.config.productionTip = false

// 官方网站： https://element.eleme.cn/#/zh-CN/component/quickstart
Vue.use(ElementUI,{size:'small',zIndex:3000});

// 自定义消息
Vue.prototype.$message = myMessage

// 打开弹窗防止页面抖动
ElementUI.Dialog.props.lockScroll.default = false; 

// vue-simple-uploader:  https://www.cnblogs.com/xiahj/p/vue-simple-uploader.html
// https://www.helloweba.net/javascript/632.html
Vue.use(uploader);
// json 格式化
Vue.use(JsonViewer);


/*全局导航守卫*/
router.beforeEach((to, from, next) => {
  if (to.path == '/'){
    next();
  }else {
    if(window.sessionStorage.getItem("userInfo")){
      initMenu(router,store);
      next();
  }else{
      next('/?redirect='+to.path);
  }
  }
})

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
